package com.example.springboot1.file;

/**
 * @author ckj
 * @description TODO
 * @date 2023-03-14 11:17
 */


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

public class LargeFileProcessor {
    public static void main(String[] args) {
        String fileName = "large_file.txt";
        long count = 0;
        long sum = 0;
        long max = Long.MIN_VALUE;
        long min = Long.MAX_VALUE;

        try (BufferedReader br = new BufferedReader(new FileReader(fileName))) {
            String line;
            while ((line = br.readLine()) != null) {
                String[] nums = line.split(",");
                for (String num : nums) {
                    long val = Long.parseLong(num);
                    count++;
                    sum += val;
                    if (val > max) {
                        max = val;
                    }
                    if (val < min) {
                        min = val;
                    }
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        double avg = (double) sum / count;
        System.out.println("Count: " + count);
        System.out.println("Sum: " + sum);
        System.out.println("Average: " + avg);
        System.out.println("Max: " + max);
        System.out.println("Min: " + min);
    }
}

